package com.imooc.api.fallbacks;

import com.imooc.api.controller.user.UserControllerApi;
import com.imooc.grance.result.GraceJsonResult;
import com.imooc.grance.result.ResponseStatusEnum;
import com.imooc.pojo.bo.UpdateUserInfoBO;
import com.imooc.pojo.vo.AppUserInfoVO;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @Project_name: imooc-news-dev
 * @Description: 降级接口
 * @Author: Levi
 * @Date: 2021/3/31 17:10
 */
@Component
public class UserControllerApiFallBack implements FallbackFactory<UserControllerApi> {

    @Override
    public UserControllerApi create(Throwable throwable) {
        return new UserControllerApi() {
            @Override
            public GraceJsonResult getUserInfo(String userId) {
                return GraceJsonResult.errorCustom(ResponseStatusEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public GraceJsonResult getCountInfo(String userId) {
                return GraceJsonResult.errorCustom(ResponseStatusEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public GraceJsonResult updateUserInfo(@Valid UpdateUserInfoBO updateUserInfoBO) {
                return GraceJsonResult.errorCustom(ResponseStatusEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public GraceJsonResult queryByIds(String userIds) {
                System.out.println("UserControllerApiFallBack : queryByIds ");
                List<AppUserInfoVO> userInfoVOList = new ArrayList<>();
                return GraceJsonResult.ok(userInfoVOList);
            }
        };
    }
}
